/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication6.DomainLayer;

/**
 *
 * @author meydlo
 */
import java.util.ArrayList;
public class SellRecords{

    private static SellRecords sellRecords;
    private ArrayList<SellProduct> sellProductList;

    //
    private SellRecords(){
        sellProductList = new ArrayList<SellProduct>();
    }

    //
    public static SellRecords getSellRecords(){
        if(sellRecords==null)
        {
            sellRecords=new SellRecords();
        }
        return sellRecords;
    }

    //
    public SellProduct createSellProduct(long productId, String name, String description, int noOfOneType, double price, double discount)
    {

        SellProduct sellProduct=new SellProduct();

        sellProduct.setDescription(description);
        sellProduct.setId(productId);
        sellProduct.setName(name);
        sellProduct.setNoOfOneType(noOfOneType);
        sellProduct.setPrice(price);
        sellProduct.setDiscount(discount);

        addSellProduct(sellProduct);
        return sellProduct;

    }

    //
    public void addSellProduct(SellProduct sellProduct)
    {
        sellProductList.add(sellProduct);
    }

    //
    public SellProduct sellProductByID(long id)
    {
        for(int i=0; i<sellProductList.size();i++){
            if(sellProductList.get(i).getId()==id)
            {
                return sellProductList.get(i);
            }
        }
        return null;
    }

    //search for sellProduct
    public SellProduct sellProductByName(String name)
    {
        for(int i=0; i<sellProductList.size();i++){
            if(sellProductList.get(i).getName().equals(name)){
                return sellProductList.get(i);
            }
        }

        System.out.println("SellProduct wasn't found");
        return null;
    }


    //
    public void deleteSellProduct(long id)
    {
        if(sellProductByID(id)!=null){
            sellProductList.remove(sellProductByID(id));
            System.out.println("product successfully removed");
        }
    }

    //
    public ArrayList<SellProduct> getSellProductList()
    {
        return sellProductList;
    }

    public void setSellProductList(ArrayList<SellProduct> list)
    {
        this.sellProductList = list;
    }


    public void printSellProductList()
    {
        if(sellProductList.size()!=0){
            for(SellProduct sellProduct : sellProductList){
                System.out.println("id: "+sellProduct.getId()+" | name: "+sellProduct.getName()+" | in stok:"+sellProduct.getNoOfOneType());
            }
        }
        else{
            System.out.println("No product for sale in list");
        }
    }


    //testing purpose
    public int getNoOfSellProducts()
    {
        int noOfSellProducts=sellProductList.size();
        return noOfSellProducts;
    }

}
